package com.lzhsite.technology.designPattern.command.RestaurantDemo;

public class HotCook implements ICook, Runnable {
	
	private String name;

	public HotCook(String name) {
		this.name = name;
	}

	public void cook(int tableNumber, String name) {
		int cookTime = (int) (20 * Math.random());
		System.out.println(this.name + " 热菜厨师正在为 " + tableNumber + " 号桌做：" + name);
		try {
			Thread.sleep(cookTime);
		} catch (InterruptedException exception) {
			exception.printStackTrace();
		}
		System.out.println(this.name + " 热菜厨师为 " + tableNumber + " 号桌做好了：" + name + "， 共计耗时 = " + cookTime + " 秒");
	}

	public void run() {
		while (true) {
			synchronized (ClientForRestaurantDemo.Lock) {
				ICommand command = CommandQueue.getOneCommand();
				if (command != null) {
					if(command instanceof DuckCommand || command instanceof ChopCommand){
						command.setCook(this);
						command.execute();
						CommandQueue.removeOneCommand();
					}

				}
			}

			try {
				Thread.sleep(1000l);
			} catch (InterruptedException exception) {
				exception.printStackTrace();
			}
		}
	}
}